import { reqGetUserInfo } from '@/api/user'
const state = {
  userInfo: {}
}
const mutations = {
  setUserInfo (state, newUserInfo) {
    state.userInfo = newUserInfo
  }
}
const actions = {
  async getUserInfo (context) {
    const res = await reqGetUserInfo()
    // console.log(res)
    const { data } = res
    console.log(data)
    if (data.code === 0) {
      context.commit('setUserInfo', data.data)
    }
  }
}
const getters = {
  userName (state) {
    return state.userInfo.nickname || state.userInfo.username
  },
  textAvatar (state) {
    return state.userInfo.username ? state.userInfo.username.slice(0, 1).toUpperCase() : ''
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
